package com.jumper.study.db.model;

import java.io.Serializable;
import java.time.LocalDateTime;

import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.jumper.study.common.api.OrderStatusCode;

//订单
@TableName("orders")
public class Order implements Serializable {
    @TableId(type = IdType.AUTO)
    private Long id;

    @TableField(updateStrategy = FieldStrategy.NEVER)
    private String orderNo;

    @TableField(updateStrategy = FieldStrategy.NEVER)
    private Long accountId;

    @TableField(updateStrategy = FieldStrategy.NEVER)
    private Long lessonId;

    @TableField(value = "`status`", insertStrategy = FieldStrategy.NOT_NULL, updateStrategy = FieldStrategy.NOT_NULL)
    private OrderStatusCode status;

    @TableField(updateStrategy = FieldStrategy.NOT_NULL)
    private Integer price;

    @TableField(insertStrategy = FieldStrategy.NEVER, updateStrategy = FieldStrategy.NEVER)
    private LocalDateTime createdAt;

    @TableField(insertStrategy = FieldStrategy.NEVER, updateStrategy = FieldStrategy.NEVER)
    private LocalDateTime updatedAt;

    @TableLogic
    private Integer deleted;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }

    public Long getAccountId() {
        return accountId;
    }

    public void setAccountId(Long accountId) {
        this.accountId = accountId;
    }

    public Long getLessonId() {
        return lessonId;
    }

    public void setLessonId(Long lessonId) {
        this.lessonId = lessonId;
    }

    public OrderStatusCode getStatus() {
        return status;
    }

    public void setStatus(OrderStatusCode status) {
        this.status = status;
    }

    public Integer getPrice() {
        return price;
    }

    public void setPrice(Integer price) {
        this.price = price;
    }

    public LocalDateTime getCreatedAt() {
        return createdAt;
    }

    public LocalDateTime getUpdatedAt() {
        return updatedAt;
    }

    public Integer getDeleted() {
        return deleted;
    }

    public void setDeleted(Integer deleted) {
        this.deleted = deleted;
    }

    //订单是否有效，并可开通课程
    @JsonIgnore
    public boolean canOpenLesson() {
        return null != status && status.getCode() == OrderStatusCode.UNPAY.getCode();
    }

    //订单是否已完成，并开通了课程
    @JsonIgnore
    public boolean lessonIsOpened() {
        return null != status && status.getCode() == OrderStatusCode.COMPLETE.getCode();
    }

    //订单是否可调价状态
    @JsonIgnore
    public boolean canUpdatePrice() {
        return null != status && status.getCode() == OrderStatusCode.UNPAY.getCode();
    }

    //是否可以取消订单
    @JsonIgnore
    public boolean canCanceled() {
        return null != status && status.getCode() == OrderStatusCode.UNPAY.getCode();
    }

    //是否可支付
    @JsonIgnore
    public boolean canPay() {
        return null != status && status.getCode() == OrderStatusCode.UNPAY.getCode();
    }
}
